package com.mark.spring.annotation.aop;

import com.mark.spring.annotation.aop.log.LogAspects;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.util.Assert;

/**
 * @Description: 日志切面引导类
 * @Author: Mark
 * @CreateDate: 2019/9/2 22:11
 * @Version: 3.00.001
 * @Copyright : 豆浆油条个人非正式工作室
 */
@ComponentScan(basePackages = {"com.mark.spring.annotation.aop"})
@EnableAspectJAutoProxy
public class AopBootstrap {

    public static void main(String[] args) {
        //加载配置，获取bean
        AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(AopBootstrap.class);

        //获取bean
        CalculatorService calculatorService = applicationContext.getBean(CalculatorService.class);
        Assert.notNull(calculatorService,"Bean is null");
        LogAspects aspects = applicationContext.getBean(LogAspects.class);
        Assert.notNull(aspects,"Bean is null");

        calculatorService.div(2 , 1);

        //关闭上下文
        applicationContext.close();

    }
}
